/**
 *====================================================
 * 文件名称: ContainerBulkstockServiceImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年10月26日	chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.common.util.BeanUtils;
import com.yuexunit.finance.common.util.DateUtils;
import com.yuexunit.finance.project.entity.ContainerBulkstockEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;

/**
 * @ClassName: ContainerBulkstockServiceImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author chenxy
 * @date 2015年10月26日 20:51:25
 */
@Implements(ContainerBulkstockService.class)
public class ContainerBulkstockServiceImpl implements ContainerBulkstockService {

	@Override
	public Long createContainerBulkstock(ContainerBulkstockEntity entity) {
		if (entity.getAbnormal() == null) {
			entity.setAbnormal(Boolean.TRUE);
		}
		entity.setCreateDateTime(DateUtils.now());
		entity.setUpdateDateTime(DateUtils.now());
		PersistUtil.insert(entity);
		return entity.getContainerBulkstockId();
	}

	@Override
	@Transactional
	public void updateContainerBulkstock(ContainerBulkstockEntity entity) {
		ContainerBulkstockEntity persist = inquireContainerBulkstock(entity.getContainerBulkstockId());
		BeanUtils.copyProperties(entity, persist);
		PersistUtil.update(persist);
	}

	@Override
	@Transactional
	public void renovateContainerBulkstock(ContainerBulkstockEntity entity) {
		PersistUtil.update(entity);
	}

	@Override
	public void deleteContainerBulkstock(Long containerBulkstockId) {
		PersistUtil.delete(ContainerBulkstockEntity.class, containerBulkstockId);
	}

	@Override
	public ContainerBulkstockEntity inquireContainerBulkstock(Long containerBulkstockId) {
		return PersistUtil.get(ContainerBulkstockEntity.class, containerBulkstockId);
	}

	@Override
	public List<ContainerBulkstockEntity> inquireContainerBulkstockList(Long inventoryId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(ContainerBulkstockEntity.class);
		criteria.add(Restrictions.eq("inventoryId", inventoryId));
		return PersistUtil.get(criteria);
	}

	@Override
	public List<ContainerBulkstockEntity> inquireContainerBulkstockList(Long inventoryId, Long bulkstockCategoryId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(ContainerBulkstockEntity.class);
		criteria.add(Restrictions.eq("inventoryId", inventoryId));
		if (bulkstockCategoryId != null) {
			criteria.add(Restrictions.eq("bulkstockCategoryId", bulkstockCategoryId));
		}
		return PersistUtil.get(criteria);
	}

	@Override
	public List<ContainerBulkstockEntity> inquireContainerBulkstockList(Long[] inventoryIds) {
		DetachedCriteria criteria = DetachedCriteria.forClass(ContainerBulkstockEntity.class);
		criteria.add(Restrictions.in("inventoryId", inventoryIds));
		return PersistUtil.get(criteria);
	}

	@Override
	public List<ContainerBulkstockEntity> inquireTallyingContainerBulkstockList(Long tallyingId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(ContainerBulkstockEntity.class);
		criteria.add(Restrictions.eq("tallyingId", tallyingId));
		return PersistUtil.get(criteria);
	}

	@Override
	public List<ContainerBulkstockEntity> inquireTransportContainerBulkstockList(Long transportNoticeId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(ContainerBulkstockEntity.class);
		criteria.add(Restrictions.eq("transportNoticeId", transportNoticeId));
		return PersistUtil.get(criteria);
	}

	@Override
	public List<ContainerBulkstockEntity> inquireContainerBulkstockListByFinanceId(Long financeId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(ContainerBulkstockEntity.class);
		criteria.add(Restrictions.eq("financeId", financeId));
		return PersistUtil.get(criteria);
	}

	@Override
	public List<ContainerBulkstockEntity> inquireContainerBulkstockListByBulkstockId(Long bulkstockId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(ContainerBulkstockEntity.class);
		criteria.add(Restrictions.eq("bulkstockId", bulkstockId));
		return PersistUtil.get(criteria);
	}
}
